package com.fix.day2aop;

import org.apache.log4j.Logger;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class MyLog4jAspect {
	
	@Pointcut("@annotation(com.fix.day2aop.LogInfo)")
	public void test() {}
	
	@Around("test() && @annotation(loginfo)")
	public Object logAround(ProceedingJoinPoint jp,LogInfo loginfo) {
		Object result = null;
		Class targetc = jp.getTarget().getClass();   // 目标对象
		String method = jp.getSignature().getName(); //目标方法名
		
//		MethodSignature sign= (MethodSignature)jp.getSignature();
//		LogInfo loginfo2 = sign.getMethod().getAnnotation(LogInfo.class);  //得到注解信息
		
		Logger log = Logger.getLogger(targetc);
		log.info(targetc+"方法名="+method);
		log.info("**********"+loginfo.value()+"**********");
		
		try {
			result = jp.proceed();
		} catch (Throwable e) {
			e.printStackTrace();
		}
		
		return result;
	}

}
